/*
 * FileName: ExceptionHandler.java
 * Author:   zzw
 * Date:     2018年05月25日
 * Description:
 */
package com.chezhibao.trace.exception;

import com.chezhibao.trace.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 〈异常统一处理〉<br>
 * 〈异常统一处理〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 */
@RestControllerAdvice
public class TraceHandler {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @ExceptionHandler(Exception.class)
    public ResponseEntity handler(Exception e){
        logger.error("error msg:",e);
        ResultVo resultVo = new ResultVo();
        resultVo.setSuccess(false);
        ResponseEntity<ResultVo> body = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultVo);
        return body;
    }
}
